package com.example.readbook.UI.Act

import android.annotation.SuppressLint
import android.view.Menu
import android.view.MenuItem
import com.example.readbook.Bean.JournalBean
import com.example.readbook.R
import com.example.readbook.Sql.JournalUtils
import com.example.readbook.UI.BaseUI.BaseActivity
import com.example.readbook.Utils.Utils
import kotlinx.android.synthetic.main.act_journal_details.*

/**
 * Package    : com.example.readbook.UI.Act
 * ClassName  : JournalDetailsActivity
 * Description: ${TODO}
 * Date       : 2019/3/26 14:50
 */
class JournalDetailsActivity : BaseActivity() {
    var bean: JournalBean? = null
    override fun getLayoutResID(): Int {
        return R.layout.act_journal_details
    }

    @SuppressLint("SetTextI18n")
    override fun initView() {
        title = "读后感详情"
        bean = intent.getSerializableExtra("bean") as JournalBean
        Act_Details_Title.text = "读《" + bean?.name + "》有感"
        Act_Details_Edit.setText(bean?.data)
    }

    override fun initListener() {
    }

    override fun initData() {
    }


    //右上角菜单点击事件监听
    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == R.id.save) {
            if (Act_Details_Edit.text.toString().isEmpty()) {
                Utils.showToast("读后感还没有写哦～")
                return true
            }
            JournalUtils.getInstence(mActivity)
                    .update(bean?.id!!, Act_Details_Edit.text.toString())
            mActivity.finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }

    //加载右上角菜单
    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.write, menu)
        return super.onCreateOptionsMenu(menu)
    }

}